#include <bits/stdc++.h>

#define fi first
#define se second
#define eb emplace_back
#define ep emplace
#define rep(i, x, y) for(int i = (x); i <= (y); i++)
#define per(i, x, y) for(int i = (x); i >= (y); i--)

using namespace std;

using ll = long long;
using pii = pair < int, int >;
using vec = vector < int >;
using veg = vector < pii >;

const int N = 3e6 + 10;

template < typename T > void chkmin(T &x, const T &y) { x = x < y ? x : y; }

int n, ndn, cnt, pre[N], suf[N], id[N];
int a[N];
vec G[N];
int low[N], dfn[N], tim, scc[N], tot, stk[N], top;
bool vis[N];

void dfs(int x) {
	low[x] = dfn[x] = ++tim; stk[++top] = x; vis[x] = true;
	for(auto y : G[x])
		if(!dfn[y]) dfs(y), chkmin(low[x], low[y]);
		else if(vis[y]) chkmin(low[x], dfn[y]);
	if(low[x] == dfn[x]) {
		int y; ++tot;
		do {
			y = stk[top--]; vis[y] = false;
			scc[y] = tot; //cerr << "BEL: " << tot << " " << y << endl;
		} while(y != x);
	}
}

int main() {
#ifdef YJR_2333_TEST
	freopen("1.in", "r", stdin);
#endif
	//ios :: sync_with_stdio(false), cin.tie(0), cout.tie(0);
	map < pii, vec > tpot;
	scanf("%d", &n); rep(i, 1, n) scanf("%d", &a[i]);
	rep(i, 1, n - 1) tpot[{ a[i], a[i + 1] }].eb(i);
	ndn = n * 2;
	rep(i, 1, n - 2) G[i].eb(i + n + 1), G[i + 1].eb(i + n);
	G[1].eb(1 + n);
	G[n - 1].eb(n + n - 1);
	for(auto t : tpot) if(t.se.size() > 1) {
			cnt = 0;
			for(auto v : t.se) id[++cnt] = v;
			/*cerr << "GET!" << cnt << endl;
			rep(j, 1, cnt) cerr << id[j] << " ";
			cerr << endl;
			*/
			rep(j, 1, cnt) {
				pre[j] = ++ndn, G[pre[j]].eb(id[j]);
				if(j > 1) G[pre[j]].eb(pre[j - 1]);
			}
			per(j, cnt, 1) {
				suf[j] = ++ndn, G[suf[j]].eb(id[j]);
				if(j < cnt) G[suf[j]].eb(suf[j + 1]);
			}
			rep(j, 1, cnt) {
				if(j > 1) G[id[j] + n].eb(pre[j - 1]);
				if(j < cnt) G[id[j] + n].eb(suf[j + 1]);
			}
		}
	//rep(i, 1, ndn) for(auto j : G[i]) cerr << i << " -> " << j << endl;
	per(i, ndn, 1) if(!low[i]) dfs(i);
	//rep(i, 1, n - 1) cerr <<"! " <<  scc[i] << " " << scc[i + n] << endl;
	
	rep(i, 1, n - 1) if(scc[i] == scc[i + n]) return puts("NO"), 0;
	vec pot;
	rep(i, 1, n - 1) if(scc[i] > scc[i + n]) pot.eb(i); 
	printf("%d\n", pot.size()); for(auto v : pot) printf("%d ", v); puts("");
}
